import java.io.IOException;
import java.io.StringReader;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;


public class CalculatorTests {
	
	@Test
	public void runOneLetter() throws IOException {
		Map<String, Integer> m = DistributionCalculator.calculate(new StringReader("aaa"), 1, 3);
		Assert.assertEquals(1, m.values().size());
		Assert.assertSame(3, m.get("a"));
		
		m = DistributionCalculator.calculate(new StringReader("aaa"), 2, 3);
		Assert.assertEquals(1, m.values().size());
		Assert.assertSame(2, m.get("aa"));
		
		m = DistributionCalculator.calculate(new StringReader("aaa"), 3, 3);
		Assert.assertEquals(1, m.values().size());
		Assert.assertSame(1, m.get("aaa"));
	}
	
	@Test
	public void runDiffLetters() throws IOException {
		Map<String, Integer> m = DistributionCalculator.calculate(new StringReader("aba"), 1, 3);
		Assert.assertEquals(2, m.values().size());
		Assert.assertSame(2, m.get("a"));
		Assert.assertSame(1, m.get("b"));
		
		m = DistributionCalculator.calculate(new StringReader("aba"), 2, 3);
		Assert.assertEquals(2, m.values().size());
		Assert.assertSame(1, m.get("ab"));
		Assert.assertSame(1, m.get("ba"));
		
		m = DistributionCalculator.calculate(new StringReader("abc"), 1, 3);
		Assert.assertEquals(3, m.values().size());
		Assert.assertSame(1, m.get("a"));
		Assert.assertSame(1, m.get("b"));
		Assert.assertSame(1, m.get("c"));
		
		m = DistributionCalculator.calculate(new StringReader("abab"), 2, 4);
		Assert.assertEquals(2, m.values().size());
		Assert.assertSame(2, m.get("ab"));
		Assert.assertSame(1, m.get("ba"));
	}
}
